﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Experimental8.Common.Data.EDM;

namespace Experimental8.Infrastructure.Helpers
{
    public static class UIBuilderHelpers
    {
        public static void MakeDataGridColumnByBDInfo(DataGridAutoGeneratingColumnEventArgs e, ObservableCollection<ui_fields_information_item> fieldsinformations)
        {
            ui_fields_information_item fieldinformation = (from f in fieldsinformations
                                                           where f.code == e.PropertyName
                                                           select f).FirstOrDefault<ui_fields_information_item>();
            if (fieldinformation == null)
                e.Cancel = true;
            try
            {
                e.Column.Header = fieldinformation.name;
                e.Column.Width = new DataGridLength(Convert.ToDouble(fieldinformation.width), DataGridLengthUnitType.Pixel);
                e.Column.IsReadOnly = (fieldinformation.read_only == null) ? true : (bool)fieldinformation.read_only;
                e.Column.Visibility = (fieldinformation.visible == true) ? Visibility.Visible : Visibility.Collapsed;
                //e.Column.DisplayIndex = (int)fieldinformation.order;
            }
            catch (Exception ex)
            {
            }
        }
    }
}
